﻿using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

namespace JQMergeFramework
{
    public class UIFailTip : MonoBehaviour
    {
        public Text recordTips;
        
        private void Start()
        {
            UIManager.Instance.AddBtnListener(this.transform);
        }
        
        
        void OnBtnClick(Transform trans)
        {
            AudioManager.Instance.Play(AudioName.Click);
            
            switch (trans.name)
            {
                case "BtnRemove":
                    Close();
                    UIManager.Instance.GetWindow<UIOver>().Open();
                    break;
                case "BtnClose":
                    Close();
                    //放弃盖楼
                    MergeManager.Instance.ClearRecord();
                    break;
            }
        }
        
        
        public void Open()
        {
            GetComponent<UIPopAnimate>().PopStart();

            //失败动画流程
            int cLv = DataManager.Instance.BuildCityIdList.Count;
            CityTargetCfg cfg =  TableConfig.Instance.GetTargetCfg(cLv);
            //TODO 盖楼提示
            recordTips.text = string.Format("距超过 <color=#BE5F2B>{0}</color>\n还差<color=#1cc902>{1}</color>层,确定放弃吗?", cfg.name, cfg.lv - cLv);
        }
        
        
        void Close()
        {
            GetComponent<UIPopAnimate>().PopEnd(); 
        }
    }
}